package com.designPatterns.proxy;

/**
 * 代理的管理由真实角色自己完成
 * Created by houjinxin on 16/3/29.
 */
public class Target4 implements ITarget4 {

    private ITarget4 proxy;

    public Target4(){}

    @Override
    public void say(String word) {
        if (isProxy()) {
            System.out.println(word);
        } else {
            System.out.println("请使用指定代理来访问");
        }
    }

    @Override
    public ITarget4 getProxy() {
        this.proxy = new StaticProxy4(this);
        return proxy;
    }

    public boolean isProxy(){
        return this.proxy != null;
    }
}
